This script will read in data from research by Alexandar et al and create graphics with a unique theme
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:flextable':
##
## style
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Figure 1
Because figure 1 has 32 rows, I recommend shortening the amount visible. In the same vein, the column “docket_text” is also quite long, so I discarded everything after the 40th character and added an ellipsis at the end of each row.
# read in figure 1 data set
figure_1 <- read_csv(paste0(data_folder, '/figure_1.csv'))
## Parsed with column specification:
## cols(
## case_number = col_character(),
## activity_date = col_character(),
## activity_number = col_integer(),
## docket_text = col_character()
## )
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 2)
## Warning: 1 parsing failure.
## row # A tibble: 1 x 5 col row col expected actual file expected <int> <chr> <chr> <chr> <chr> actual 1 52802 <NA> 4 columns 3 columns '../data/Alexander_et_al/figure_1.csv' file # A tibble: 1 x 5
# subset data by selecting all the rows in which are not NA in column 'case_number'
figure_1 <- figure_1[!is.na(figure_1$case_number),]
# figure 1 in the paper has 3 more columns than what is available in the data
# shorten the last column and add '...' to not blow up the table
figure_1$docket_text <- paste0(substr(figure_1$docket_text, 1, 40), '...')
# create a dummy row for the table
dummy_row <- c('...', '...', '...', '...')
last_row <- figure_1[nrow(figure_1),]
# combine with a subsetted version of figure 1 for the table appearance
figure_1_sub <- figure_1[1:10, ]
figure_1_table <- rbind(figure_1_sub,
dummy_row,
last_row)
# generate a latex table as suggested in the paper using kable
kable(figure_1_table, caption = 'Figure 1') %>%
kable_styling(bootstrap_options = c("condensed", 'striped'),
full_width = TRUE)
Figure 1
|
case_number
|
activity_date
|
activity_number
|
docket_text
|
|
1:10-cv-00002-ODE
|
1/4/2010
|
1
|
NOTICE OF REMOVAL with COMPLAINT, filed …
|
|
1:10-cv-00002-ODE
|
1/5/2010
|
2
|
Unopposed MOTION for Extension of Time t…
|
|
1:10-cv-00002-ODE
|
1/5/2010
|
3
|
ORDER granting 2 Motion for Extension of…
|
|
1:10-cv-00002-ODE
|
1/29/2010
|
4
|
ANSWER to 1 NOTICE OF REMOVAL with Compl…
|
|
1:10-cv-00002-ODE
|
1/29/2010
|
5
|
Certificate of Interested Persons by Chi…
|
|
1:10-cv-00002-ODE
|
2/2/2010
|
6
|
Guidelines for Discovery and Motion Prac…
|
|
1:10-cv-00002-ODE
|
2/23/2010
|
7
|
Joint PRELIMINARY REPORT AND DISCOVERY P…
|
|
1:10-cv-00002-ODE
|
2/27/2010
|
8
|
Initial Disclosures by Emmanuel Nketop.(…
|
|
1:10-cv-00002-ODE
|
3/2/2010
|
9
|
Initial Disclosures by Children’s Health…
|
|
1:10-cv-00002-ODE
|
3/5/2010
|
10
|
Certificate of Interested Persons by Emm…
|
|
…
|
…
|
…
|
…
|
|
1:10-cv-00002-ODE
|
10/13/2010
|
NA
|
Civil Case Terminated. Magistrate Judge …
|
Figures 4
# read in figure 4 and 7 data set
figure_4_7 <- read.xlsx(paste0(data_folder, '/figure_4_7.xlsx'), sheetName = 1)
# split data up into figure_4 and figure_7
figure_4 <- figure_4_7[,1:2]
rm(figure_4_7)
# recode names of columns
names(figure_4) <- c('variable', 'percentage')
# convert percents to percentage form round
figure_4$percentage <- round((figure_4$percentage*100))
# create two separate data sets for figure_4 for the two pie charts in the paper
figure_4_1 <- figure_4[grepl('Exemption|Color|Race|National|Religion|Sex|Retaliation', figure_4$variable),]
figure_4_2 <- figure_4[grepl('Indian|Middle|Hispanic|Asian|African|Native', figure_4$variable),]
rm(figure_4)
# # reorder factors
# figure_4_1$variable <- factor(figure_4_1$variable, levels = c('Retaliation', 'Exemption', 'Color', 'Race', 'National origin', 'Religion', 'Sex'))
# figure_4_1$variable <- as.character(figure_4_1$variable)
# get font object for plot
f <- list(
size = 13,
color = "#A9A9A9"
)
title_f <- list(
size = 16,
color = "black"
)
# get a gray scale color vector for the pie chart
colors <- gray.colors(length(unique(figure_4_1$variable)))
# use plotly's R pakage to create tow side by side pie charts
plot_ly(figure_4_1 ,labels = ~variable, values = ~percentage,
type ='pie',
hole = 0,
text= ~variable,
textposition = 'outside',
outsidetextfont = f,
height = 800, width = 1200,
domain = list(x = c(0, 0.4), y = c(0, 1)),
marker = list(colors = colors,
line = list(color = '#FFFFFF', width = 0.5))) %>%
add_pie(data = figure_4_2, labels = ~variable, values = ~percentage,
domain = list(x = c(0.6, 1), y = c(0, 1))) %>%
config(displayModeBar = F) %>%
layout(title ='' , font = title_f,showlegend = F,
annotations = list(
showarrow = FALSE,
text = ''),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
margin = list(l = 50, r = 50, b = 50, t = 50))